
//
//  SearchTextField.m
//  黑马微博-wzy
//
//  Created by Mac on 2016/12/4.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "SearchTextField.h"

@implementation SearchTextField

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
            self.width = 300;
            self.height = 30;
            self.background = [UIImage resizedImage:@"searchbar_textfield_background"];
            //设置内容 垂直居中
            self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            //设置左边显示的放大镜
            UIImageView *leftImageView = [[UIImageView alloc] init];
            leftImageView.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
            leftImageView.width = self.height;
            leftImageView.height = self.height;
            //设置 leftView的内容居中
            leftImageView.contentMode = UIViewContentModeCenter;
            self.leftView = leftImageView;
            //设置 左边的view 永远显示
            self.leftViewMode = UITextFieldViewModeAlways;
            //设置 右边 永远显示 清除 按钮
            self.clearButtonMode = UITextFieldViewModeAlways;
 
    }
    return self;
}


+ (instancetype)searchTextField{
    //init 会调用 - (instancetype)initWithFrame:(CGRect)frame 方法
    return [[self alloc] init];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
